How to Delete a local Branch on Git
Git ready to delete a local branch!
I get it. Git has specific ways to communicate our needs. It is a new language to novices like me who are entering the programming world. I knew that my question, "Why can't I just delete a file instead of deleting a "branch" anyway?!?" would always lead me to a path of "You're going to learn it if you want to be a developer homegirl." There is no arguing about, "Why Can't We just...?" The only option is to learn it and be a "git teacher" to others to be proficient at git. There's so much to learn, journal I must. Share I shall. Teach I will. The yoda in me will conquer this git with you and overcome this new world of git beginning with: "Deleting a Branch on Git." Image by Ribastank from Pixabay
This tutorial is based on using the visual code studio's terminal (VSC) where you enter the commands from a repository copied from Github. At anytime we enter a command in the terminal, we follow the command with the enter key. We do not surround our command with any quotation marks. We do not need periods after the command (at least for this example and in majority of commands).
FIRST: How do we know which branch we need to remove? We do this by typing: git branch. (We do not need to type a period after the command in the terminal.) Your terminal will reflect your name and your github user name before the $. Below shows an example with my name as the owner of the example terminal and my github user before the $. We do not need to enter the latter information as it will automatically reflect this information on your terminal.
SECOND: Once you hit enter, you'll find an asterisk * noted on the current branch you are viewing. In this example, there are 2 branches & 1 master branch. There is 1 branch called "almarose/techblog1" & "almarose/techblog2." We need to delete the "almarose/techblog2" branch. (Extra credit if you remembered NOT to put quotation marks around the command and did not add a period at the end of the command.)
THIRD: On your terminal, type: "git branch -d branch-name-you-want-to-delete." You will get a confirmation on your terminal that your branch is deleted. Remember: Do not include the quotations around the command! (NOTICE: There are no quotation marks surrounding commands & does not have a period after the command. It just says: git branch.)
To have a clean view of your terminal and to double-confirm that the branch has been deleted, type: "git branch" to see what branches still exist. Remember: Pat yourself on the back if you did not put quotations around the command. See example:
CONGRATULATIONS!!! YOU ARE A GIT STAR !!! You have just successfully deleted a local branch on git using the VSC! I'm proud of you!!! Image by rawpixel from Pixabay
TO RECAP: (1) Follow your commands with the Enter key. (2) To view which branch you are currently viewing: Git branch. (3) To delete a local branch: git branch -d branch-name-you-want-to-delete.
Thank you for taking this git journey with me ! Best of luck in your programming adventures!
Almarose Revives
Almarose has served people with special needs for over 10 years. She has been in the Speech & Language Pathology field helping to form communication using Augmentative & Alternative Communication (AAC) devices and educational apps as an Assistive Technology Specialist. One of her dreams is to work remotely as a Website Accessibility Consultant & a Full-Stack Developer upon completion from Moms Can Code. And the other is to play tennis like a boss--watch out Serena & Venus! The best dream come true has been becoming a mother to her baby boy.Learn Digital Skills
Find out when the next cohort begins!
The most comprehensive program to up your game in the remote career world.
Learn More